from unittest import TestCase
from ddt  import ddt,data,unpack
from selenium import webdriver
from ManagementOperation import ManagementOperation
from Management_data import Management_data

@ddt
class Test4Management(TestCase):
#########################################################################################
###################################      零钱理财       ###################################

    @data(*Management_data.Management_small_change_data)
    @unpack
    def testManagement1(self,username,password,payment_password,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        ma = ManagementOperation()
        before = ma.management_before(driver,username,password,case)
        money = ma.small_change(driver)
        after = ma.management_after(driver,payment_password,before[0],before[1],money)
        result = ma.getResult(after[0],after[1])

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)

#########################################################################################
###################################      期限理财       ###################################

    @data(*Management_data.Management_term_data)
    @unpack
    def testManagement2(self,username,password,payment_password,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        ma = ManagementOperation()
        before = ma.management_before(driver,username,password,case)
        money = ma.term(driver)
        after = ma.management_after(driver,payment_password,before[0],before[1],money)
        result = ma.getResult(after[0],after[1])

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)

#########################################################################################
###################################      基金理财       ###################################

    @data(*Management_data.Management_fund_data)
    @unpack
    def testManagement3(self,username,password,payment_password,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        ma = ManagementOperation()
        before = ma.management_before(driver,username,password,case)
        money = ma.fund(driver)
        after = ma.management_after(driver,payment_password,before[0],before[1],money)
        result = ma.getResult(after[0],after[1])

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)

#########################################################################################
###################################    银行卡支付测试    ###################################

    @data(*Management_data.Management_card_edit_data)
    @unpack
    def testManagement4(self,username,password,payment_password,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        ma = ManagementOperation()
        before = ma.management_before(driver,username,password,case)
        money = ma.fund(driver)
        after = ma.management_after(driver,payment_password,before[0],before[1],money)
        result = ma.getResult(after[0],after[1])

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)